package cn.tedu.csmall.passport.repo;

import cn.tedu.csmall.passport.pojo.vo.RoleListItemVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * IRoleRedisRepository的实现类
 */
@Slf4j
@Repository
public class RoleRedisRepositoryIml implements IRoleRedisRepository{

    @Autowired
    private RedisTemplate<String, Serializable> redisTemplate;

    public RoleRedisRepositoryIml(){
        log.debug("创建处理缓存的数据访问对象: RoleRedisRepositoryIml");
    }

    @Override
    public void save(List<RoleListItemVO> list) {
        String keys = ROLE_LIST_KEY;
        ListOperations ops = redisTemplate.opsForList();
        for (RoleListItemVO vo : list) {
            ops.rightPush(keys, vo);
        }
    }

    @Override
    public void deleteAll() {
        String keys = ROLE_LIST_KEY;
        redisTemplate.delete(keys);
    }

    @Override
    public List<RoleListItemVO> list() {
        Long start = 0L;
        Long end = -1L;
        return list(start, end);
    }

    @Override
    public List<RoleListItemVO> list(Long start, Long end) {
        String key = ROLE_LIST_KEY;
        ListOperations ops = redisTemplate.opsForList();
        return ops.range(key, start, end);
    }


//    @Override
//    public void list(List<RoleListItemVO> list) {
//        //redis中的key
//        String keys = ROLE_LIST_KEY;
//        redisTemplate.opsForList()
//    }
}
